package com.hu.zhcc.shiro.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.dao.HMemberofthefileMapper;
import com.hu.zhcc.shiro.entity.bo.HMemberofthefile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class HMemberofthefileServiceImpl implements HMemberofthefileService {

    @Autowired
    private HMemberofthefileMapper hMemberofthefileMapper;

    @Override
    public int deleteByPrimaryKey(Integer hId) {
        return hMemberofthefileMapper.deleteByPrimaryKey(hId);
    }

    @Override
    public int insertSelective(HMemberofthefile record) {
        return hMemberofthefileMapper.insertSelective(record);
    }

    @Override
    public HMemberofthefile selectByPrimaryKey(Integer hId) {
        return hMemberofthefileMapper.selectByPrimaryKey(hId);
    }

    @Override
    public Page<HMemberofthefile> findhmList(int pageIndex, int num ,String value) {
        PageHelper.startPage(pageIndex,num);
        List<HMemberofthefile> hmList = hMemberofthefileMapper.selectByPrimaryName(value);
        PageInfo<HMemberofthefile> pageInfo = new PageInfo<>(hmList);
        return new Page<HMemberofthefile>(pageInfo.getTotal(),hmList);
    }

    @Override
    public Page<HMemberofthefile> findhmListNuon(int pageIndex, int num,String value, Map map) {
        PageHelper.startPage(pageIndex,num);
        if(value.equals("b")){
            Date now = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String format = dateFormat.format(now);

            Calendar calendar = new GregorianCalendar();

            calendar.setTime(new Date());

            calendar.add(Calendar.DATE,-2);

            String date2= dateFormat.format(calendar.getTime());
            map.put("startTime", date2);
            map.put("endTime", format);
        }
        List<HMemberofthefile> hmList = hMemberofthefileMapper.selectByPrimaryNoun(map);


        PageInfo<HMemberofthefile> pageInfo = new PageInfo<>(hmList);
        return new Page<HMemberofthefile>(pageInfo.getTotal(),hmList);
    }

    @Override
    public int updateByPrimaryKeySelective(HMemberofthefile record) {
        return hMemberofthefileMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public HMemberofthefile login(HMemberofthefile record) {
        return hMemberofthefileMapper.login(record);
    }

    @Override
    public HMemberofthefile select(String s) {
        return hMemberofthefileMapper.select(s);
    }
}
